﻿using Fuse8.ContentManagementFramework.Domain;
using Fuse8.ContentManagementFramework.Domain.Commands;
using Fuse8.ContentManagementFramework.Domain.Commands.CommandParameters;
using Fuse8.ContentManagementFramework.Domain.Special;
using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.Common.Locator;
using System.Collections.Generic;

namespace Fuse8.ContentManagementFramework.BizFacade.Services
{
    public class CmsMediaContentService : CmsSiteBusinessService<CmsMediaContent>
    {
        public void AddMany(IEnumerable<CmsAdminMediaContent> mediaContents, int mediaId = 0)
        {
            Guard.ArgumentNotNull(mediaContents, "mediaContents");

            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaContentCreateCommand>();

            var commandParameter = new CmsMediaContentCreateCommandParameter
            {
                MediaId = mediaId,
                MediaContents = mediaContents
            };

            TrackingEntityObjectMediator.TrackEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            command.Execute();
        }

        public IEnumerable<CmsMediaContent> FindByKeywords(string keywords, int? mediaId = null)
        {
            Guard.ArgumentNotEmpty(keywords, "keywords");

            var command = DependencyServiceLocator.Current.GetInstance<CmsMediaContentFindByKeywordsCommand>();

            var commandParameter = new CmsMediaContentFindByKeywordsCommandParameter
            {
                MediaId = mediaId,
                SearchQuery = keywords
            };

            SiteAwareEntityObjectMediator.SetSiteEntity(commandParameter);

            command.ConfigureCommand(commandParameter);

            return Find(command);
        }
    }
}